package com.swucq.gitlearning;

public class InsertSort {
    private int[] data;
    public int[] getData() {
        return data;
    }

    public void setData(int[] data) {
        this.data = data;
    }

    public InsertSort(int[] data) {
        this.data = data;
    }
//直接插入法排序
    private void insertSort(){
        int temp=0;
        for(int a=1;a<data.length;a++){
            for(int j=a;j>0;j--){
                if(data[j]<data[j-1]){
                    temp=data[j];
                    data[j]=data[j-1];
                    data[j-1]=temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] a={34,12,90,12,12,22,10,6,29,162,1,20};
        InsertSort insertSort=new InsertSort(a);
        insertSort.insertSort();
        for (int x:a){
            System.out.print(x+" ");
        }
        System.out.println();


    }
}
